package com.css.zfzx.fwsjcj.modules.user.repository;

import com.css.zfzx.fwsjcj.commen.util.Constant;
import com.css.zfzx.fwsjcj.modules.user.entity.FwUserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author Leon
 */
@Repository
public interface FwUserRepository extends JpaRepository<FwUserEntity, String> {
    @Modifying
    @Query(nativeQuery = true, value = "update fw_user set is_valid ='" + Constant.IS_VALID_NO + "',update_time = :updateTime where id IN :ids")
    void deleteByIds(@Param("ids") List<String> ids, @Param("updateTime") Date updateTime);

    @Modifying
    @Query(nativeQuery = true, value = "update fw_user set status =:type where id in :ids")
    void updateType(@Param("ids") List<String> ids, @Param("type") String type);

    @Modifying
    @Query(nativeQuery = true, value = "update fw_user set base_user_Id =:baseUserId where id =:id")
    void updateById(@Param("id") String id, @Param("baseUserId") String baseUserId);

    FwUserEntity findByUserName(String userName);

    FwUserEntity findByIdNumber(String idNumber);

    FwUserEntity findByMobilePhone(String idNumber);

    FwUserEntity findByBaseUserId(String baseUserId);

    /**
     * 物理删除
     *
     * @param ids
     */
    @Modifying
    @Transactional
    @Query(nativeQuery = true, value = "delete from fw_user where id in (?1)")
    void deleteBatch(List<String> ids);
}
